/**
 * Copyright (c) 2016-2019 人人开源 All rights reserved.
 *
 * https://www.renren.io
 *
 * 版权所有，侵权必究！
 */

package io.renren.modules.app.interceptor;


import io.renren.common.exception.RRException;
import io.renren.modules.app.annotation.BimLogin;
import io.renren.modules.app.service.BimRequestService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;

/**
 * 权限(Token)验证
 *
 * @author Mark sunlightcs@gmail.com
 */
@Component
public class BimAuthorizationInterceptor extends HandlerInterceptorAdapter {
    @Autowired
    private BimRequestService bimRequestService;

    public static final String USER_KEY = "userId";

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        BimLogin annotation;
        if(handler instanceof HandlerMethod) {
            annotation = ((HandlerMethod) handler).getMethodAnnotation(BimLogin.class);
        }else{
            return true;
        }

        if(annotation == null){
            return true;
        }

//        if(bimRequestService.checkAccount( new HashMap<>())){
//            throw new RRException( "用户账号密码错误", HttpStatus.UNAUTHORIZED.value());
//        }

        return true;
    }
}
